<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
        #drawMobile{
        	width:300px;
        	height:100px;
        	background: green;
        	color:white;
        	font-size:2em;
        	text-align: center;
        	margin:100px auto;
        	line-height: 100px;
        	border-radius: 20px;
        }
        #drawButton{
        	padding:12px 20px;
        	background: pink;
        	border:none;
        	text-align: center;
        	width:100px;
            margin:100px auto;
        	border-radius: 10px;
        }
        #button3{
        	margin:10px auto;
        }
	</style>
</head>
<body>
	<div id="drawMobile">
		17809213656
	</div>
	<div id="drawButton">
		<input type="button" id="button1" value="抽奖" onclick="startDraw()">
		<input type="button" id="button2" value="停止" onclick="stopDraw()">
		<input type="button" id="button3" value="显示中奖号码" onclick="stopDraw()">
	</div>
	<script>
      
        var button1=document.getElementById("button1");
        var button2=document.getElementById("button2");
        var newArr=[];
        var count=100;
        var timeId;
        var drawMobile=[];  //保存已经中奖的号码
        var tempMobile='';  //临时保存每一抽取过程中的手机号
        var tempIndex='';  //临时保存每一抽取过程中的手机号的下标
        var flag=false;
        //手机号中第二位可以取的值
        var secondMobile=[3,5,7,8];

        //随机生成count个手机号码-作为测试
        for(var i=0; i<count; i++){
            var mobile='1';
            var index=Math.floor(Math.random()*4);
            mobile+=secondMobile[index];

            for(var j=0; j<9; j++){
            	mobile+=Math.floor(Math.random()*10);
            }
            	newArr.push(mobile);

            }
        function randomMobile(){
            var len=newArr.length;
            var index=Math.floor(Math.random()*len);
            var mobile=newArr[index];
            tempMobile=mobile;
            tempIndex=index;
            document.getElementById('drawMobile').innerHTML=mobile.substr(0,3)+'****'+mobile.substr(7);
            }
            randomMobile();
        function startDraw(){
            document.getElementById('drawMobile').innerHTML='';
            timeId=setInterval(randomMobile,80);
            }
        function stopDraw(){
            flag=false;
            //保存抽奖号码
            drawMobile.push(tempMobile);
            //从原数组中删除已经中奖的号码
            newArr.splice(tempIndex,1);
            clearInterval(timeId);
            }
        function show(){
            var str='';
            for(var i=0; i< drawMobile.length; i++){
                  
            }
           }



        //     for(var i=0; i<10; i++){
        //       var randomMobile=Math.floor(Math.random()*9);
        //       var reg=/^1[34578]\d{9}&/;
             
        //       document.getElementById('drawMobile').innerHTML=randomMobile;
        //       // newArr.join();
        //     }
           
        	
        // }
	</script>
</body>
</html>